package com.app.service.impl;

import com.app.entity.Category;
import com.app.mapper.CategoryMapper;
import com.app.service.CategoryService;
import com.app.util.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lkg
 * @since 2021-04-14
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Result getList() {
        return Result.success(categoryMapper.selectList(null));
    }

    @Override
    public Result updateCatalogByAdmin(Category category) {
        if (StringUtils.isNotEmpty(category.getCid())) {
            categoryMapper.updateById(category);
            return Result.success();
        }
        categoryMapper.insert(category);
        return Result.success();
    }
}
